package com.atguigu.flow.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.flow.comm.ExcelConst;
import com.atguigu.flow.entity.DTO.Productphoto;
import com.atguigu.flow.entity.QuotationsLine;
import com.atguigu.flow.entity.vo.*;
import com.atguigu.flow.mapper.QuotationsLineMapper;
import com.atguigu.flow.service.QuotationsLineService;
import com.atguigu.flow.utils.ExcelUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import sun.misc.BASE64Encoder;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author testjava
 * @since 2023-05-24
 */
@Service
public class QuotationsLineServiceImpl extends ServiceImpl<QuotationsLineMapper, QuotationsLine> implements QuotationsLineService {

    @Override
    public
    List<QuotationsLine> getsell_well_items(String fromrq, String torq) {
       return baseMapper.getsell_well_items(fromrq,torq);
    }

    @Override
    public
    List<GlassShipments> grass_ship_find(String fromrq, String torq,String supplierno) {
        return baseMapper.grass_ship_find(fromrq,torq,supplierno);
    }


    @Override
    public
    List<GlassShipments_detail> grass_ship_find_detail(String fromrq, String torq,String supplierno) {
        return baseMapper.grass_ship_find_detail(fromrq,torq,supplierno);
    }

    @Override
    public List<GlassShipments_detail> dl_zsdd_detail() {
        return baseMapper.dl_zsdd_detail();
    }

    @Override
    public
    List<Productphoto> getproductandimage(String itemno) {
        return baseMapper.getproductandimage(itemno);
    }

    @Override
    public
    List<LuProductShipments> Lvproduct_shipList() {
        return baseMapper.Lvproduct_shipList();
    }

    @Override
    public
    JSONObject productimaglist(String itemno) throws Exception {
        List<Productphoto> dataList = baseMapper.getproductandimage(itemno);
        System.out.println(dataList);
        List<JSONObject> headList = new ArrayList<>();


        List<List<String>> lists = new ArrayList<>();
        JSONObject jsonObject = new JSONObject();

        jsonObject = new JSONObject();
        jsonObject.put(ExcelConst.TITLE, "产品编号");
        jsonObject.put(ExcelConst.WIDTH, 13 * 256);
        jsonObject.put(ExcelConst.TYPE, "1");
        headList.add(jsonObject);

        jsonObject = new JSONObject();

        jsonObject.put(ExcelConst.TITLE, "图片");
        jsonObject.put(ExcelConst.WIDTH, 13 * 256);
        jsonObject.put(ExcelConst.TYPE, "1");
        headList.add(jsonObject);
        for (int i = 0; i < dataList.size(); i++) {
            //if (StringUtils.isEmpty(dataList.get(i).getPhoto())) continue;
            List<String> list = new ArrayList<>();

            list.add(dataList.get(i).getItemNo());
            BASE64Encoder base64Encoder = new BASE64Encoder();
            if (!StringUtils.isEmpty(dataList.get(i).getPhoto()))
                list.add(base64Encoder.encode(dataList.get(i).getPhoto()));
            else
                list.add(base64Encoder.encode("empty".getBytes()));

            lists.add(list);

        }
        String path="d:\\库存产品导出.xlsx";
        ExcelUtil.getExcel(path, lists, headList,true);
        jsonObject = new JSONObject();
        jsonObject.put("importurl",path);
        return jsonObject;
    }

    @Override
    public
    List<HscodeShipments> gethscode_amount(String hscode) {
        return baseMapper.gethscode_amount(hscode);
    }

    @Override
    public List<Purchaseorderslist> getpurchaseorderslist(String fromrq, String torq, String PurchaseOrderNo,String Province,String City) {
        return baseMapper.getpurchaseorderslist(fromrq,torq,PurchaseOrderNo,Province,City);
    }
}
